# dict
d = {}
print(bool(d))  # False
# k-v
d = {"name": "老王", "gender": "男", "hobby": "翻墙"}

# 增加
d["height"] = 1.56
print(d)
# 删除
d.pop("gender")
print(d)
# 查
print(d["name"])
# 改
d["name"] = "老宋"
print(d)

# -------额外用法-------------------
# d1 = d.copy()  # 深拷贝
# print(d1)
# print(d.items())  # 获取所有的键值对
# print(d.keys())  # 获取所有的键
# print(d.values())  # 获取所有的值
#
# print(d.get("name1"))  # 遇到不存在的键值对会返回None
# print(d["name1"])  # 遇到不存在会报错

# 删除一对，随机（不是运行一次，随机删除一个，因为字典没有序）
# d.popitem()
# print(d)

# print(d)
# d.setdefault("name1", "老李")  # key存在不更新，key不存在则添加
# print(d)

# 字典合并
# d.update({"a": 1, "b": 2, "name": "老段"})
# print(d)

#  遍历

for i in d:
    print(i)
    print(d.get(i))

for i in d.items():
    print(i)
    print(i[0])
    print(i[1])

# a, b = 1, 2
# a, b = (1, 2)
# a, b = [1, 2]
# for k, v in d.items():
#     print(k, v)

# for i in d.keys():
#     print(i)

# for i in d.values():
#     print(i)




